package com.game.gateway.messages;

import com.game.gateway.channel.GameMessageServerContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.DefaultApplicationArguments;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class GameMessageServerBoot {

    public static GameMessageServerContext messageServerContext;
    private static ApplicationContext applicationContext;
    private static ApplicationArguments arguments;
    private static boolean isStarted;

    private GameMessageServerBoot() {}

    public void run(ApplicationContext context, String[] arguments) {
        GameMessageServerBoot.arguments = new DefaultApplicationArguments(arguments);
        GameMessageServerBoot.applicationContext = context;
        if(messageServerContext == null){
            messageServerContext = new GameMessageServerContext(context);
        }
        isStarted = true;
        log.info("服务启动成功");
    }

    public static void setApplicationContext(ApplicationContext context) {
        GameMessageServerBoot.applicationContext = context;
    }

    public static ApplicationContext getApplicationContext() {
        return applicationContext;
    }

    public static ApplicationArguments getArguments() {
        return arguments;
    }

    public static void setArguments(ApplicationArguments arguments) {
        GameMessageServerBoot.arguments = arguments;
    }
    public static GameMessageServerContext getMessageServerContext() {
        return messageServerContext;
    }

    public static void setMessageServerContext(GameMessageServerContext messageServerContext) {
        GameMessageServerBoot.messageServerContext = messageServerContext;
    }


    public static boolean isIsStarted() {
        return isStarted;
    }

    public static void setIsStarted(boolean isStarted) {
        GameMessageServerBoot.isStarted = isStarted;
    }
}
